package com.zju.springboot.db.redis;

import com.zju.springboot.db.redis.bean.Address;
import com.zju.springboot.db.redis.bean.Person;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.*;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author 况祥彬
 * @date 2020/12/4 23:41
 **/
@RunWith(SpringRunner.class)
@SpringBootTest
public class redisConfigTest {

    @Autowired
    private StringRedisTemplate srt;

//    @Autowired
//    private RedisTemplate<String,Person> rt;
    private RedisConfig rt;

    @Resource(name="redisTemplate")
    private ValueOperations<String,Object> valueOperations;

    @Resource(name = "redisTemplate")
    private HashOperations<String, String, Object> hashOperations;

    @Resource(name = "redisTemplate")
    private ListOperations<String, Object> listOperations;

    @Resource(name = "redisTemplate")
    private SetOperations<String, Object> setOperations;

    @Resource(name = "redisTemplate")
    private ZSetOperations<String, Object> zSetOperations;

    @Test

    public void stringRedisTemplate() {
        Person person = new Person("kk", "wy");
        person.setAddress(new Address("杭州", "中国"));
        //将数据存入redis数据库
        rt.redisTemplate(new LettuceConnectionFactory()).opsForValue().set("k",person);

        srt.opsForValue().set("name","kk",20, TimeUnit.SECONDS);



    }
}
